<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateQiiGuestbookFieldsTable extends Migration
{
    /**
     * Schema table name to migrate
     * @var string
     */
    public $set_schema_table = 'qii_guestbook_fields';

    /**
     * Run the migrations.
     * @table qii_guestbook_fields
     *
     * @return void
     */
    public function up()
    {
        if (Schema::hasTable($this->set_schema_table)) return;
        Schema::create($this->set_schema_table, function (Blueprint $table) {
            $table->engine = 'InnoDB';
            $table->increments('id')->comment('ID');
            $table->unsignedInteger('category_id')->default('0')->comment('类型id');
            $table->char('fieldname', 30)->default('')->comment('字段名');
            $table->char('fieldtype', 15)->default('')->comment('字段类型');
            $table->char('itemname', 20)->default('')->comment('字段提示文字');
            $table->char('strlen', 20)->default('')->comment('字符数( 例：1,100 )');
            $table->unsignedTinyInteger('valid')->default('0')->comment('是否必填（必填1, 非必填0）');
            $table->text('valdefault')->nullable()->default(null)->comment('默认值');
            $table->text('preg')->nullable()->default(null)->comment('正则验证');
            $table->unsignedTinyInteger('list_show')->default('0')->comment('显示在后台列表（显示1, 不显示0）');
            $table->text('data')->nullable()->default(null)->comment('序列化扩展字段');
            $table->unsignedInteger('sortrank')->default('0')->comment('字段排序');

            $table->index(["category_id", "sortrank"], 'category_sort');

            $table->unique(["category_id", "fieldname"], 'category_fieldname');
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
     public function down()
     {
       Schema::dropIfExists($this->set_schema_table);
     }
}
